#include "CowString.hpp"
#include <iostream>

using std::cout;
using std::endl;

void test0(){
    CowString str1("hello");
    CowString str2("world");
    CowString str3(str1);
    cout << "str1:" << str1 << endl;
    cout << "str2:" << str2 << endl;
    cout << "str3:" << str3 << endl;
    cout << str1.useCount() << endl;
    cout << str2.useCount() << endl;
    cout << str3.useCount() << endl;
}

void test1(){
    CowString str1("helloworld");
    cout << str1.useCount() << endl;
    CowString str2(str1);
    cout << "str1:" << str1 << endl;
    cout << "str2:" << str2 << endl;
    cout << str1.useCount() << endl;
    cout << str2.useCount() << endl;

    cout << str1.c_str() << endl;
    cout << str2.c_str() << endl;

    cout << str1.size() << endl;
    cout << str2.size() << endl;
}

void test2(){
    CowString str1("hello");
    CowString str2("world");
    CowString str3(str1);
    cout << "str1:" << str1 << endl;
    cout << "str2:" << str2 << endl;
    cout << "str3:" << str3 << endl;
    cout << str1.useCount() << endl;
    cout << str2.useCount() << endl;
    cout << str3.useCount() << endl;

    str2 = str1;
    str1 = str1;
    cout << "str1:" << str1 << endl;
    cout << str1.useCount() << endl;
    cout << "str2:" << str2 << endl;
    cout << str2.useCount() << endl;
}

void test3(){
    CowString str1("hello");
    cout << str1.useCount() << endl;
    cout << "str1[0]:" << str1[0] << endl;
    cout << "str1[0]:" << str1[6] << endl;
}

void test4(){
    CowString str1("hello");
    cout << str1.useCount() << endl;
    CowString str2 = str1;
    cout << "str1:" << str1 << endl;
    cout << "str2:" << str2 << endl;
    cout << str1.useCount() << endl;
    cout << str2.useCount() << endl;

    str1[0] = 'X';
    // cout << "str1:" << str1 << endl;
    // cout << "str2:" << str2 << endl;
    // cout << str1.useCount() << endl;
    // cout << str2.useCount() << endl;

    cout << "str1:" << str1 << endl;
    cout << "str2:" << str2 << endl;
    cout << "str1[0]:" << str1[0] << endl;
    cout << "str2[0]:" << str2[0] << endl;
    cout << str1.useCount() << endl;
    cout << str2.useCount() << endl;
}

void test5(){
    CowString str1("hello");
    CowString str2 = str1;
    str1[0] = 'h';
    cout << str1.useCount() << endl;
    cout << str2.useCount() << endl;
}

int main(void){
    test5();
    return 0;
}